Skip to content

Treat explicit markup lines as non-titles in RST parser - #1335

Merged
jaapio merged 2 commits into
phpDocumentor:mainfrom
lacatoire:feature/forgiving-anchor-parsing
Aug 28, 2026
Merged

Treat explicit markup lines as non-titles in RST parser#1335
jaapio merged 2 commits into
phpDocumentor:mainfrom
lacatoire:feature/forgiving-anchor-parsing

Conversation

@lacatoire

Copy link
Copy Markdown
Contributor

Closes #1240.

When an anchor (or any explicit markup line like a comment or directive) sits directly above a section underline without an intervening blank line, the parser used to greedily treat the markup line as the section title text. With this change, TitleRule::applies() skips lines that start with .. followed by whitespace (or a lonely ..), so the body rules (e.g. LinkRule) can claim them and the next paragraph becomes the actual title, exactly as docutils does.

Validated by a new integration fixture anchor-no-blank-line/ covering both single-space and double-space anchors directly above section titles.

When a line starting with '..' (anchor, comment, directive) is followed
directly by a section underline without a blank line, the parser used
to treat the whole markup line as the title text. It now skips title
detection on explicit markup lines so the appropriate body rule
(LinkRule, CommentRule, ...) can claim them, and the next paragraph
becomes the section title.

Closes phpDocumentor#1240
Hosts the helper next to its siblings (isLink, isDirective, isAnnotation),
aligns its regex flags with the rest of the file, and exercises
sub-section underlines, phrase-reference anchors and stacked anchors.
@jaapio
jaapio force-pushed the feature/forgiving-anchor-parsing branch from ddbb022 to 3b447af Compare August 28, 2026 11:32
@jaapio
jaapio enabled auto-merge August 28, 2026 11:32
@jaapio

jaapio commented Aug 28, 2026

Copy link
Copy Markdown
Member

Thanks for fixing this issue!

@jaapio
jaapio merged commit 83909c4 into phpDocumentor:main Aug 28, 2026
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Be more forgiving in specifying anchors

2 participants